home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Oct, 2000
- // Author: bb
- //
- // Procedure Name:
- // mergeCharacters
- //
- // Description:
- // Merge multiple characters into a single character. If multiple
- // characters are selected and some of the characters are subcharacters
- // of another of the characters, the subcharacters will be merged
- // into the highest level character. If none of the characters are
- // subcharacters, the merge will be into the last selected character.
- //
- // Input Arguments:
- // none: works on the selection list
- //
- // Return Value:
- // name of the character that the other characters were merged to
- //
-
- proc string[]
- findParentChar(string $chars[])
- //
- // Given a list of characters, recursively find those which are parents of
- // other characters in the list. Keep going til you find the most
- // parent characters of all.
- //
- {
- int $charCount = size($chars);
- string $parentChar[];
- int $ii, $jj;
- for ($ii = 0; $ii < $charCount; $ii++) {
- $parentChar[$ii] = "";
- for ($jj = 0; $jj < $charCount; $jj++) {
- if ($ii == $jj) continue;
- if (`character -isMember $chars[$jj] $chars[$ii]`) {
- $parentChar[$ii] = $chars[$jj];
- break;
- }
- }
- }
-
- string $pc;
- int $sizeCompressed = 0;
- string $compressedParents[];
- for ($ii = 0; $ii < $charCount; $ii++) {
- if ("" != $parentChar[$ii]) {
- $compressedParents[$sizeCompressed] = $parentChar[$ii];
- $sizeCompressed++;
- }
- }
-
- // continue searching for parents until one or less is found
- //
- if (size($compressedParents) < 2) {
- return $compressedParents;
- } else {
- string $newParents[];
- $newParents = findParentChar($compressedParents);
- if (size($newParents) == 0) {
- return $compressedParents;
- } else {
- return $newParents;
- }
- }
- }
-
- global proc string
- mergeCharacters()
- // Description:
- // Merge multiple characters into a single character. If multiple
- // characters are selected and some of the characters are subcharacters
- // of another of the characters, the subcharacters will be merged
- // into the highest level character. If none of the characters are
- // subcharacters, the merge will be into the last selected character.
- //
- {
- // Check for the proper selection -> two or more characters
- //
- string $chars[] = `ls -sl -type character`;
- int $charCount = size($chars);
- if ($charCount < 2) {
- error("Select the characters to be merged.");
- return "";
- }
-
- // Find the character to merge to (highest character in hierarchy,
- // or if there are no subcharacters, just use the last selected character)
- //
- string $mergeChar;
- string $parentChars[] = findParentChar($chars);
- if (size($parentChars)) {
- $mergeChar = $parentChars[size($parentChars)-1];
- } else {
- $mergeChar = $chars[$charCount-1];
- }
-
- string $character;
- for ($character in $chars) {
- if ($character == $mergeChar) continue;
-
- string $mem;
- string $members[] = `character -q $character`;
- string $attrs[];
- clear $attrs;
- for ($mem in $members) {
- if (nodeType($mem) != "character") {
- $attrs[size($attrs)] = $mem;
- }
- }
-
- // transfer the attrs to the destination character
- //
- character -e -fe $mergeChar $members;
-
- // delete the source character
- //
- delete $character;
- }
-
-
- return $mergeChar;
- }
-